#ifndef DIFERENCIAL_H_INCLUDED
#define DIFERENCIAL_H_INCLUDED

#include <string>
#include <sstream>
#define END "@"

class Diferencial{
    private:
    std::string DeltaContenido;
    int Nmatch; //SI VALE -1, es algo que quedo al final !!!!
    //el bloque del receptor que matcheo con el del emisor, luego del Delta
    public:

    Diferencial(const std::string& s,int n):DeltaContenido(s),Nmatch(n){}
    Diferencial(const std::string& ser)
    {
        this->Hidratar(ser);
    }
    Diferencial(){};
    ~Diferencial(){}

    std::string getDelta(){return this->DeltaContenido;}
    int getNmatch(){return this->Nmatch;}

    void Hidratar(const std::string& str)
    {
        std::stringstream SS(str);
        unsigned int LongDelta = 0;
        SS >> LongDelta;

        char* buffer = new char[LongDelta+1];

        buffer[LongDelta]='\0';
        SS.ignore(1,EOF);
        SS.read(buffer,LongDelta);
        std::string delta(buffer);

        delete [] buffer;

        this->DeltaContenido=delta;
        SS >> this->Nmatch;
    }

    std::string Serializar()
    {
        std::string Bytes;
        std::string aux;
        std::stringstream SS("");
        SS << this->DeltaContenido.size();
        //std::cout << "DeltSize "<< this->DeltaContenido.size() << std::endl ;
        SS >> Bytes;
        Bytes.append(" ");
        Bytes.append( this->DeltaContenido );
        SS.clear();
        SS << this->Nmatch;
        //std::cout << "Nmatch "<< this->Nmatch << std::endl;
        SS >> aux;
        Bytes.append(aux);
        Bytes.append(END);
        return Bytes;
    }
};

#endif // DIFERENCIA_H_INCLUDED
